package com.lyl.domaindemo.resource.user.dto.response;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.lyl.domaindemo.Infrastructure.Constants;
import com.lyl.domaindemo.domain.user.User;
import lombok.*;

/**
 * @author lyl
 * @date 2023/5/18
 */

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class UserResponse {

    @JsonProperty(value = "id")
    private Long id;

    @JsonProperty(value = "username")
    private String username;

    @JsonProperty(value = "password")
    private String password;

    @JsonProperty(value = "sex")
    private String sex;

    public static UserResponse of(User user) {
        return UserResponse.builder()
                .id(user.getId())
                .username(user.getUsername())
                .sex(user.getSex().equals(0) ? Constants.SEX_MAN : Constants.SEX_WOMAN)
                .build();
    }
}
